package com.changgou.service.goods.controller;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.changgou.common.pojo.Result;
import com.changgou.common.pojo.StatusCode;
import com.changgou.service.goods.service.SpecService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Resource
    private SpecService specService;



    /**
     * 根据商品分类名称查询规格列表。
     * @param category   前端传来的商品名称。
     * @return  返回规格列表。
     */
    @GetMapping("/category/{category}")
    public Result findListByCategroyName(@PathVariable("category") String category){
        if(StrUtil.isEmpty(category)){
            return new Result(false,StatusCode.ERROR,"category为空，无法查询");
        }

        List<Map> specList = this.specService.findListByCategroyName(category);
        if(ObjUtil.isEmpty(specList)){
            return new Result(false,StatusCode.ERROR,"没有查询到");
        }


        return new Result(true, StatusCode.OK,"",specList);
    }
}
